/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author eltorre
 */
@Entity
@Table(name = "Pujas")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Puja.findAll", query = "SELECT p FROM Puja p"),
    @NamedQuery(name = "Puja.findById", query = "SELECT p FROM Puja p WHERE p.pujaPK.id = :id"),
    @NamedQuery(name = "Puja.findByPseudonimo", query = "SELECT p FROM Puja p WHERE p.pseudonimo = :pseudonimo"),
    @NamedQuery(name = "Puja.findByCantidad", query = "SELECT p FROM Puja p WHERE p.cantidad = :cantidad"),
    @NamedQuery(name = "Puja.findByFecha", query = "SELECT p FROM Puja p WHERE p.fecha = :fecha"),
    @NamedQuery(name = "Puja.findByIdCore", query = "SELECT p FROM Puja p WHERE p.idCore = :idCore"),
    @NamedQuery(name = "Puja.findBySubasta", query = "SELECT p FROM Puja p WHERE p.pujaPK.subasta = :subasta")})
public class Puja implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PujaPK pujaPK;
    @Basic(optional = false)
    @Column(name = "pseudonimo")
    private String pseudonimo;
    @Basic(optional = false)
    @Column(name = "cantidad")
    private long cantidad;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecha;
    @Basic(optional = false)
    @Column(name = "idCore")
    private int idCore;
    @JoinColumn(name = "subasta", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Subasta subasta1;
    @JoinColumn(name = "usuario", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Usuarios usuario;

    public Puja() {
    }

    public Puja(PujaPK pujaPK) {
        this.pujaPK = pujaPK;
    }

    public Puja(PujaPK pujaPK, String pseudonimo, long cantidad, Date fecha, int idCore) {
        this.pujaPK = pujaPK;
        this.pseudonimo = pseudonimo;
        this.cantidad = cantidad;
        this.fecha = fecha;
        this.idCore = idCore;
    }

    public Puja(int id, int subasta) {
        this.pujaPK = new PujaPK(id, subasta);
    }

    public PujaPK getPujaPK() {
        return pujaPK;
    }

    public void setPujaPK(PujaPK pujaPK) {
        this.pujaPK = pujaPK;
    }

    public String getPseudonimo() {
        return pseudonimo;
    }

    public void setPseudonimo(String pseudonimo) {
        String oldPseudonimo = this.pseudonimo;
        this.pseudonimo = pseudonimo;
        changeSupport.firePropertyChange("pseudonimo", oldPseudonimo, pseudonimo);
    }

    public long getCantidad() {
        return cantidad;
    }

    public void setCantidad(long cantidad) {
        long oldCantidad = this.cantidad;
        this.cantidad = cantidad;
        changeSupport.firePropertyChange("cantidad", oldCantidad, cantidad);
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        Date oldFecha = this.fecha;
        this.fecha = fecha;
        changeSupport.firePropertyChange("fecha", oldFecha, fecha);
    }

    public int getIdCore() {
        return idCore;
    }

    public void setIdCore(int idCore) {
        int oldIdCore = this.idCore;
        this.idCore = idCore;
        changeSupport.firePropertyChange("idCore", oldIdCore, idCore);
    }

    public Subasta getSubasta1() {
        return subasta1;
    }

    public void setSubasta1(Subasta subasta1) {
        Subasta oldSubasta1 = this.subasta1;
        this.subasta1 = subasta1;
        changeSupport.firePropertyChange("subasta1", oldSubasta1, subasta1);
    }

    public Usuarios getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuarios usuario) {
        Usuarios oldUsuario = this.usuario;
        this.usuario = usuario;
        changeSupport.firePropertyChange("usuario", oldUsuario, usuario);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pujaPK != null ? pujaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Puja)) {
            return false;
        }
        Puja other = (Puja) object;
        if ((this.pujaPK == null && other.pujaPK != null) || (this.pujaPK != null && !this.pujaPK.equals(other.pujaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Puja[ pujaPK=" + pujaPK + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
